// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router'
import routers from './routes'
import iView from 'iview'
import VueCookie from 'vue-cookie'
import 'iview/dist/styles/iview.css'

Vue.config.productionTip = false

// Tell Vue to use the plugin
Vue.use(VueCookie);
Vue.use(VueRouter);
Vue.use(iView);

// 路由配置
const RouterConfig = {
    mode: 'history',
    routes: routers
};

const router = new VueRouter(RouterConfig);

// router.beforeEach((to, from, next) => {
//     window.document.title = to.meta.title;
//     if (to.matched.some(record => record.meta.noAuth)) {
//         iView.LoadingBar.start();
//         next();
//     } else {
//         //检查是否存在session
//         if(!Vue.cookie.get('is_login')){
//             //如果没有登录状态则跳转到登录页
//             router.replace('/login');
//         }else{
//             //否则跳转到登录后的页面
//             iView.LoadingBar.start();
//             next();
//         }
//     }
// });

router.afterEach(() => {
    iView.LoadingBar.finish();
    window.scrollTo(0, 0);
});


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router: router,
  render: h => h(App)
});